<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>18.4. Using Google Calendar</title>
<link rel="stylesheet" href="dbstyle.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="Programmer's Reference Guide">
<link rel="up" href="zend.gdata.html" title="Chapter 18. Zend_Gdata">
<link rel="prev" href="zend.gdata.clientlogin.html" title="18.3. Authenticating with ClientLogin">
<link rel="next" href="zend.gdata.docs.html" title="18.5. Using Google Documents List Data API">
<link rel="chapter" href="introduction.html" title="Chapter 1. Introduction to Zend Framework">
<link rel="chapter" href="zend.acl.html" title="Chapter 2. Zend_Acl">
<link rel="chapter" href="zend.auth.html" title="Chapter 3. Zend_Auth">
<link rel="chapter" href="zend.cache.html" title="Chapter 4. Zend_Cache">
<link rel="chapter" href="zend.config.html" title="Chapter 5. Zend_Config">
<link rel="chapter" href="zend.console.getopt.html" title="Chapter 6. Zend_Console_Getopt">
<link rel="chapter" href="zend.controller.html" title="Chapter 7. Zend_Controller">
<link rel="chapter" href="zend.currency.html" title="Chapter 8. Zend_Currency">
<link rel="chapter" href="zend.date.html" title="Chapter 9. Zend_Date">
<link rel="chapter" href="zend.db.html" title="Chapter 10. Zend_Db">
<link rel="chapter" href="zend.debug.html" title="Chapter 11. Zend_Debug">
<link rel="chapter" href="zend.dojo.html" title="Chapter 12. Zend_Dojo">
<link rel="chapter" href="zend.dom.html" title="Chapter 13. Zend_Dom">
<link rel="chapter" href="zend.exception.html" title="Chapter 14. Zend_Exception">
<link rel="chapter" href="zend.feed.html" title="Chapter 15. Zend_Feed">
<link rel="chapter" href="zend.filter.html" title="Chapter 16. Zend_Filter">
<link rel="chapter" href="zend.form.html" title="Chapter 17. Zend_Form">
<link rel="chapter" href="zend.gdata.html" title="Chapter 18. Zend_Gdata">
<link rel="chapter" href="zend.http.html" title="Chapter 19. Zend_Http">
<link rel="chapter" href="zend.infocard.html" title="Chapter 20. Zend_InfoCard">
<link rel="chapter" href="zend.json.html" title="Chapter 21. Zend_Json">
<link rel="chapter" href="zend.layout.html" title="Chapter 22. Zend_Layout">
<link rel="chapter" href="zend.ldap.html" title="Chapter 23. Zend_Ldap">
<link rel="chapter" href="zend.loader.html" title="Chapter 24. Zend_Loader">
<link rel="chapter" href="zend.locale.html" title="Chapter 25. Zend_Locale">
<link rel="chapter" href="zend.log.html" title="Chapter 26. Zend_Log">
<link rel="chapter" href="zend.mail.html" title="Chapter 27. Zend_Mail">
<link rel="chapter" href="zend.measure.html" title="Chapter 28. Zend_Measure">
<link rel="chapter" href="zend.memory.html" title="Chapter 29. Zend_Memory">
<link rel="chapter" href="zend.mime.html" title="Chapter 30. Zend_Mime">
<link rel="chapter" href="zend.openid.html" title="Chapter 31. Zend_OpenId">
<link rel="chapter" href="zend.paginator.html" title="Chapter 32. Zend_Paginator">
<link rel="chapter" href="zend.pdf.html" title="Chapter 33. Zend_Pdf">
<link rel="chapter" href="zend.registry.html" title="Chapter 34. Zend_Registry">
<link rel="chapter" href="zend.rest.html" title="Chapter 35. Zend_Rest">
<link rel="chapter" href="zend.search.lucene.html" title="Chapter 36. Zend_Search_Lucene">
<link rel="chapter" href="zend.server.html" title="Chapter 37. Zend_Server">
<link rel="chapter" href="zend.service.html" title="Chapter 38. Zend_Service">
<link rel="chapter" href="zend.session.html" title="Chapter 39. Zend_Session">
<link rel="chapter" href="zend.soap.html" title="Chapter 40. Zend_Soap">
<link rel="chapter" href="zend.test.html" title="Chapter 41. Zend_Test">
<link rel="chapter" href="zend.text.html" title="Chapter 42. Zend_Text">
<link rel="chapter" href="zend.timesync.html" title="Chapter 43. Zend_TimeSync">
<link rel="chapter" href="zend.translate.html" title="Chapter 44. Zend_Translate">
<link rel="chapter" href="zend.uri.html" title="Chapter 45. Zend_Uri">
<link rel="chapter" href="zend.validate.html" title="Chapter 46. Zend_Validate">
<link rel="chapter" href="zend.version.html" title="Chapter 47. Zend_Version">
<link rel="chapter" href="zend.view.html" title="Chapter 48. Zend_View">
<link rel="chapter" href="zend.xmlrpc.html" title="Chapter 49. Zend_XmlRpc">
<link rel="appendix" href="requirements.html" title="Appendix A. Zend Framework Requirements">
<link rel="appendix" href="coding-standard.html" title="Appendix B. Zend Framework Coding Standard for PHP">
<link rel="appendix" href="copyrights.html" title="Appendix C. Copyright Information">
<link rel="index" href="the.index.html" title="Index">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar.connecting" title="18.4.1. Connecting To The Calendar Service">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar_retrieval" title="18.4.2. Retrieving A Calendar List">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.event_retrieval" title="18.4.3. Retrieving Events">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar.creating_events" title="18.4.4. Creating Events">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar.modifying_events" title="18.4.5. Modifying Events">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar.deleting_events" title="18.4.6. Deleting Events">
<link rel="subsection" href="zend.gdata.calendar.html#zend.gdata.calendar.comments" title="18.4.7. Accessing Event Comments">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader"><table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">18.4. Using Google Calendar</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="zend.gdata.clientlogin.html">Prev</a> </td>
<th width="60%" align="center">Chapter 18. Zend_Gdata</th>
<td width="20%" align="right"> <a accesskey="n" href="zend.gdata.docs.html">Next</a>
</td>
</tr>
</table></div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="zend.gdata.calendar"></a>18.4. Using Google Calendar</h2></div></div></div>
<p>
        You can use the
        <code class="code">Zend_Gdata_Calendar</code>
        class to view, create, update, and delete events in the online Google Calendar service.
    </p>
<p>
        See
        <a href="http://code.google.com/apis/calendar/overview.html" target="_top">http://code.google.com/apis/calendar/overview.html</a>
        for more information about the Google Calendar API.
    </p>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar.connecting"></a>18.4.1. Connecting To The Calendar Service</h3></div></div></div>
<p>
            The Google Calendar API, like all GData APIs, is based off of the Atom Publishing Protoco (APP),
            an XML based format for managing web-based resources. Traffic between a client and the Google
            Calendar servers occurs over HTTP and allows for both authenticated and unauthenticated connections.
        </p>
<p>
            Before any transactions can occur, this connection needs to be made. Creating a connection to the
            calendar servers involves two steps: creating an HTTP client and binding a
            <code class="code">Zend_Gdata_Calendar</code>
            service instance to that client.
        </p>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.connecting.authentication"></a>18.4.1.1. Authentication</h4></div></div></div>
<p>
                The Google Calendar API allows access to both public and private calendar feeds. Public feeds
                do not require authentication, but are read-only and offer reduced functionality. Private feeds
                offers the most complete functionality but requires an authenticated connection to the calendar
                servers. There are three authentication schemes that are supported by Google Calendar:
            </p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                        <em class="firstterm">ClientAuth</em>
                        provides direct username/password authentication to the
                        calendar servers. Since this scheme requires that users
                        provide your application with their password, this
                        authentication is only recommended when other
                        authentication schemes are insufficient.
                    </p></li>
<li><p>
                        <em class="firstterm">AuthSub</em>
                        allows authentication to the calendar servers via a
                        Google proxy server. This provides the same level of
                        convenience as ClientAuth but without the security
                        risk, making this an ideal choice for web-based
                        applications.
                    </p></li>
<li><p>
                        <em class="firstterm">MagicCookie</em>
                        allows authentication based on a semi-random URL
                        available from within the Google Calendar interface.
                        This is the simplest authentication scheme to
                        implement, but requires that users manually retrieve
                        their secure URL before they can authenticate, doesn't
                        provide access to calendar lists, and is limited to
                        read-only access.
                    </p></li>
</ul></div>
<p>
                The
                <code class="code">Zend_Gdata</code>
                library provides support for all three authentication schemes.
                The rest of this chapter will assume that you are familiar the
                authentication schemes available and how to create an
                appropriate authenticated connection. For more information,
                please see section the
                <a href="zend.gdata.html#zend.gdata.introduction.authentication" title="18.1.4. Google Data Client Authentication">Authentication section</a>
                of this manual or the
                <a href="http://code.google.com/apis/gdata/auth.html" target="_top">Authentication Overview in the Google Data API Developer's Guide</a>.
            </p>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.connecting.service"></a>18.4.1.2. Creating A Service Instance</h4></div></div></div>
<p>
                In order to interact with Google Calendar, this library provides the
                <code class="code">Zend_Gdata_Calendar</code> service class. This class provides a common interface to the
                Google Data and Atom Publishing Protocol models and assists in marshaling requests to and from
                the calendar servers.
            </p>
<p>
                Once deciding on an authentication scheme, the next step is to create an instance of
                <code class="code">Zend_Gdata_Calendar</code>. The class constructor takes an instance of
                <code class="code">Zend_Http_Client</code> as a single argument. This provides an interface for AuthSub
                and ClientAuth authentication, as both of these require creation of a special authenticated
                HTTP client. If no arguments are provided, an unauthenticated instance of
                <code class="code">Zend_Http_Client</code> will be automatically created.
            </p>
<p>The example below shows how to create a Calendar service class using ClientAuth authentication:</p>
<pre class="programlisting">&lt;?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');

// Parameters for ClientAuth authentication
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "sample.user@gmail.com";
$pass = "pa$$w0rd";

// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);

// Create an instance of the Calendar service
$service = new Zend_Gdata_Calendar($client);
            </pre>
<p>A Calendar service using AuthSub can be created in a similar, though slightly more lengthy fashion:</p>
<pre class="programlisting">&lt;?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');

/** Retrieve the current URL so that the AuthSub server knows where to
 * redirect the user after authentication is complete.
 */
function getCurrentUrl()
{
    global $_SERVER;

    // Filter php_self to avoid a security vulnerability.
    $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);

    if (isset($_SERVER['HTTPS']) &amp;&amp; strtolower($_SERVER['HTTPS']) == 'on') {
        $protocol = 'https://';
    } else {
        $protocol = 'http://';
    }
    $host = $_SERVER['HTTP_HOST'];
    if ($_SERVER['HTTP_PORT'] != '' &amp;&amp;
        (($protocol == 'http://' &amp;&amp; $_SERVER['HTTP_PORT'] != '80') ||
        ($protocol == 'https://' &amp;&amp; $_SERVER['HTTP_PORT'] != '443'))) {
        $port = ':' . $_SERVER['HTTP_PORT'];
    } else {
        $port = '';
    }
    return $protocol . $host . $port . $php_request_uri;
}

/** Obtain an AuthSub authenticated HTTP client, redirecting the user to the
 *  AuthSub server to login if necessary.
 */
function getAuthSubHttpClient()
{
    global $_SESSION, $_GET;

    // If there is no AuthSub session or one-time token waiting for us,
    // redirect the user to the AuthSub server to get one.
    if (!isset($_SESSION['sessionToken']) &amp;&amp; !isset($_GET['token'])) {
        // Parameters to give to AuthSub server
        $next = getCurrentUrl();
        $scope = "http://www.google.com/calendar/feeds/";
        $secure = false;
        $session = true;

        // Redirect the user to the AuthSub server to sign in

        $authSubUrl = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
         header("HTTP/1.0 307 Temporary redirect");

         header("Location: " . $authSubUrl);

         exit();
    }

    // Convert an AuthSub one-time token into a session token if needed
    if (!isset($_SESSION['sessionToken']) &amp;&amp; isset($_GET['token'])) {
        $_SESSION['sessionToken'] =
            Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
    }

    // At this point we are authenticated via AuthSub and can obtain an
    // authenticated HTTP client instance

    // Create an authenticated HTTP client
    $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
    return $client;
}

// -&gt; Script execution begins here &lt;-

// Make sure http://code.google.com/apis/gdata/reference.html#Queriesthat the user has a valid session, so we can record the
// AuthSub session token once it is available.
session_start();

// Create an instance of the Calendar service, redirecting the user
// to the AuthSub server if necessary.
$service = new Zend_Gdata_Calendar(getAuthSubHttpClient());
            </pre>
<p>Finally, an unauthenticated server can be created for use with either public feeds or MagicCookie authentication:</p>
<pre class="programlisting">&lt;?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Calendar');


// Create an instance of the Calendar service using an unauthenticated HTTP client

$service = new Zend_Gdata_Calendar();
            </pre>
<p>
                Note that MagicCookie authentication is not supplied with the HTTP connection, but is instead
                specified along with the desired visibility when submitting queries. See the section on retrieving
                events below for an example.
            </p>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar_retrieval"></a>18.4.2. Retrieving A Calendar List</h3></div></div></div>
<p>
            The calendar service supports retrieving a list of calendars for the authenticated user. This is
            the same list of calendars which are displayed in the Google Calendar UI, except those marked as
            "<code class="code">hidden</code>" are also available.
        </p>
<p>
            The calendar list is always private and must be accessed over an authenticated connection. It is
            not possible to retrieve another user's calendar list and it cannot be accessed using MagicCookie
            authentication. Attempting to access a calendar list without holding appropriate credentials will
            fail and result in a 401 (Authentication Required) status code.
        </p>
<pre class="programlisting">&lt;?php
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata_Calendar($client);

try {
    $listFeed= $service-&gt;getCalendarListFeed();
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}
        </pre>
<p>
            Calling <code class="code">getCalendarListFeed()</code> creates a new instance of
            <code class="code">Zend_Gdata_Calendar_ListFeed</code> containing each available calendar as an instance of
            <code class="code">Zend_Gdata_Calendar_ListEntry</code>. After retrieving the feed, you can use the iterator
            and accessors contained within the feed to inspect the enclosed calendars.
        </p>
<pre class="programlisting">&lt;?php
echo "&lt;h1&gt;Calendar List Feed&lt;/h1&gt;";
echo "&lt;ul&gt;";
foreach ($listFeed as $calendar) {
    echo "&lt;li&gt;" . $calendar-&gt;title . " (Event Feed: " . $calendar-&gt;id . ")&lt;/li&gt;";
}
echo "&lt;/ul&gt;";
        </pre>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.event_retrieval"></a>18.4.3. Retrieving Events</h3></div></div></div>
<p>
            Like the list of calendars, events are also retrieved using the <code class="code">Zend_Gdata_Calendar</code>
            service class. The event list returned is of type <code class="code">Zend_Gdata_Calendar_EventFeed</code>
            and contains each event as an instance of <code class="code">Zend_Gdata_Calendar_EventEntry</code>. As before,
            the iterator and accessors contained within the event feed instance allow inspection of individual
            events.
        </p>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.event_retrieval.queries"></a>18.4.3.1. Queries</h4></div></div></div>
<p>
                When retrieving events using the Calendar API, specially constructed query URLs are used to
                describe what events should be returned. The <code class="code">Zend_Gdata_Calendar_EventQuery</code>
                class simplifies this task by automatically constructing a query URL based on provided
                parameters. A full list of these parameters is available at the
                <a href="http://code.google.com/apis/gdata/reference.html#Queries" target="_top">Queries section of the Google Data APIs Protocol Reference</a>
                . However, there are three parameters that are worth special attention:
            </p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                        <em class="firstterm">User</em>
                        is used to specify the user whose calendar is being
                        searched for, and is specified as an email address. If
                        no user is provided, "default" will be used instead to
                        indicate the currently authenticated user (if
                        authenticated).
                    </p></li>
<li><p>
                        <em class="firstterm">Visibility</em>
                        specifies whether a users public or private calendar
                        should be searched. If using an unauthenticated session
                        and no MagicCookie is available, only the public feed
                        will be available.
                    </p></li>
<li><p>
                        <em class="firstterm">Projection</em>
                        specifies how much data should be returned by the
                        server and in what format. In most cases you will want
                        to use the "full" projection. Also available is the
                        "basic" projection, which places most meta-data into
                        each event's content field as human readable text, and
                        the "composite" projection which includes complete text
                        for any comments alongside each event. The "composite"
                        view is often much larger than the "full" view.
                    </p></li>
</ul></div>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.event_retrieval.start_time"></a>18.4.3.2. Retrieving Events In Order Of Start Time</h4></div></div></div>
<p>
                The example below illustrates the use of the <code class="code">Zend_Gdata_Query</code> class and specifies
                the private visibility feed, which requires that an authenticated connection is available to
                the calendar servers. If a MagicCookie is being used for authentication, the visibility should
                be instead set to "<code class="code">private-magicCookieValue</code>", where magicCookieValue is the random
                string obtained when viewing the private XML address in the Google Calendar UI. Events are
                requested chronologically by start time and only events occurring in the future are returned.
            </p>
<pre class="programlisting">&lt;?php
$query = $service-&gt;newEventQuery();
$query-&gt;setUser('default');
// Set to $query-&gt;setVisibility('private-magicCookieValue') if using MagicCookie auth
$query-&gt;setVisibility('private');
$query-&gt;setProjection('full');
$query-&gt;setOrderby('starttime');
$query-&gt;setFutureevents('true');

// Retrieve the event list from the calendar server
try {
    $eventFeed = $service-&gt;getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}

// Iterate through the list of events, outputting them as an HTML list
echo "&lt;ul&gt;";
foreach ($eventFeed as $event) {
    echo "&lt;li&gt;" . $event-&gt;title . " (Event ID: " . $event-&gt;id . ")&lt;/li&gt;";
}
echo "&lt;/ul&gt;";
            </pre>
<p>
                Additional properties such as ID, author, when, event status, visibility, web content,
                and content, among others are available within <code class="code">Zend_Gdata_Calendar_EventEntry</code>.
                Refer to the
                <a href="http://framework.zend.com/apidoc/core/" target="_top">Zend Framework API Documentation</a>
                and the
                <a href="http://code.google.com/apis/gdata/reference.html" target="_top">Calendar Protocol Reference</a>
                for a complete list.
            </p>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.event_retrieval.date_range"></a>18.4.3.3. Retrieving Events In A Specified Date Range</h4></div></div></div>
<p>
                To print out all events within a certain range, for example from December 1, 2006 through
                December 15, 2007, add the following two lines to the previous sample. Take care to remove
                "<code class="code">$query-&gt;setFutureevents('true')</code>", since´<code class="code">futureevents</code> will override
                <code class="code">startMin</code> and <code class="code">startMax</code>.
            </p>
<pre class="programlisting">&lt;?php
$query-&gt;setStartMin('2006-12-01');
$query-&gt;setStartMax('2006-12-16');
            </pre>
<p>
                Note that <code class="code">startMin</code> is inclusive whereas <code class="code">startMax</code>
                is exclusive. As a result, only events through 2006-12-15 23:59:59 will be returned.
            </p>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.event_retrieval.fulltext"></a>18.4.3.4. Retrieving Events By Fulltext Query</h4></div></div></div>
<p>
                To print out all events which contain a specific word, for example "dogfood", use the
                <code class="code">setQuery()</code>
                method when creating the query.
            </p>
<pre class="programlisting">&lt;?php
$query-&gt;setQuery("dogfood");
            </pre>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.event_retrieval.individual"></a>18.4.3.5. Retrieving Individual Events</h4></div></div></div>
<p>
                Individual events can be retrieved by specifying their event ID as part of the query. Instead
                of calling <code class="code">getCalendarEventFeed()</code>, <code class="code">getCalendarEventEntry()</code>
                should be called instead.
            </p>
<pre class="programlisting">&lt;?php
$query = $service-&gt;newEventQuery();
$query-&gt;setUser('default');
$query-&gt;setVisibility('private');
$query-&gt;setProjection('full');
$query-&gt;setEvent($eventId);

try {
    $event = $service-&gt;getCalendarEventEntry($query);
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}
            </pre>
<p>
                In a similar fashion, if the event URL is known, it can be passed directly into
                <code class="code">getCalendarEntry()</code>
                to retrieve a specific event. In this case, no query object is required since the event
                URL contains all the necessary information to retrieve the event.
            </p>
<pre class="programlisting">&lt;?php
$eventURL = "http://www.google.com/calendar/feeds/default/private/full/g829on5sq4ag12se91d10uumko";

try {
    $event = $service-&gt;getCalendarEventEntry($eventURL);
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}
            </pre>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar.creating_events"></a>18.4.4. Creating Events</h3></div></div></div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.creating_events.single"></a>18.4.4.1. Creating Single-Occurrence Events</h4></div></div></div>
<p>
                Events are added to a calendar by creating an instance of <code class="code">Zend_Gdata_EventEntry</code>
                and populating it with the appropriate data. The calendar service instance
                (<code class="code">Zend_Gdata_Calendar</code>) is then used to used to transparently covert the event
                into XML and POST it to the calendar server. Creating events requires either an AuthSub
                or ClientAuth authenticated connection to the calendar server.
            </p>
<p>At a minimum, the following attributes should be set:</p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                        <em class="firstterm">Title</em>
                        provides the headline that will appear above the event
                        within the Google Calendar UI.
                    </p></li>
<li><p>
                        <em class="firstterm">When</em>
                        indicates the duration of the event and, optionally,
                        any reminders that are associated with it. See the next
                        section for more information on this attribute.
                    </p></li>
</ul></div>
<p>Other useful attributes that may optionally set include:</p>
<div class="itemizedlist"><ul type="disc">
<li><p>
                        <em class="firstterm">Author</em>
                        provides information about the user who created the
                        event.
                    </p></li>
<li><p>
                        <em class="firstterm">Content</em>
                        provides additional information about the event which
                        appears when the event details are requested from
                        within Google Calendar.
                    </p></li>
<li><p>
                        <em class="firstterm">EventStatus</em>
                        indicates whether the event is confirmed, tentative, or
                        canceled.
                    </p></li>
<li><p>
                        <em class="firstterm">Hidden</em>
                        removes the event from the Google Calendar UI.
                    </p></li>
<li><p>
                        <em class="firstterm">Transparency</em>
                        indicates whether the event should be consume time on
                        the user's free/busy list.
                    </p></li>
<li><p>
                        <em class="firstterm">WebContent</em>
                        allows links to external content to be provided within
                        an event.
                    </p></li>
<li><p>
                        <em class="firstterm">Where</em>
                        indicates the location of the event.
                    </p></li>
<li><p>
                        <em class="firstterm">Visibility</em>
                        allows the event to be hidden from the public event
                        lists.
                    </p></li>
</ul></div>
<p>
                For a complete list of event attributes, refer to the
                <a href="http://framework.zend.com/apidoc/core/" target="_top">Zend Framework API Documentation</a>
                and the
                <a href="http://code.google.com/apis/gdata/reference.html" target="_top">Calendar Protocol Reference</a>.
                Attributes that can contain multiple values, such as where, are implemented as arrays and need
                to be created accordingly. Be aware that all of these attributes require objects as parameters.
                Trying instead to populate them using strings or primitives will result in errors during conversion
                to XML.
            </p>
<p>
                Once the event has been populated, it can be uploaded to the calendar server by passing it as an
                argument to the calendar service's <code class="code">insertEvent()</code> function.
            </p>
<pre class="programlisting">&lt;?php
// Create a new entry using the calendar service's magic factory method
$event= $service-&gt;newEventEntry();

// Populate the event with the desired information
// Note that each attribute is crated as an instance of a matching class
$event-&gt;title = $service-&gt;newTitle("My Event");
$event-&gt;where = array($service-&gt;newWhere("Mountain View, California"));
$event-&gt;content = $service-&gt;newContent(" This is my awesome event. RSVP required.");

// Set the date using RFC 3339 format.
$startDate = "2008-01-20";
$startTime = "14:00";
$endDate = "2008-01-20";
$endTime = "16:00";
$tzOffset = "-08";

$when = $service-&gt;newWhen();
$when-&gt;startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00";
$when-&gt;endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00";
$event-&gt;when = array($when);

// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$newEvent = $service-&gt;insertEvent($event);
            </pre>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.creating_events.schedulers_reminders"></a>18.4.4.2. Event Schedules and Reminders</h4></div></div></div>
<p>
                An event's starting time and duration are determined by the value of its when property, which
                contains the properties <code class="code">startTime</code>, <code class="code">endTime</code>, and <code class="code">valueString</code>.
                <code class="code">StartTime</code> and <code class="code">EndTime</code> control the duration of the event, while
                <code class="code">valueString</code> provides a way to store a friendly, human readable version of the
                duration such as "This Afternoon". Note that even when using <code class="code">valueString</code>,
                <code class="code">startTime</code> and <code class="code">endTime</code> still must be be set to valid values.
            </p>
<p>
                All-day events can be scheduled by specifying only the date omitting the time when setting
                <code class="code">startTime</code>
                and
                <code class="code">endTime</code>
                . Likewise, zero-duration events can be specified by omitting the
                <code class="code">endTime</code>
                . In all cases, date/time values should be provided in
                <a href="http://www.ietf.org/rfc/rfc3339.txt" target="_top">RFC3339</a>
                format.
            </p>
<pre class="programlisting">&lt;?php
// Schedule the event to occur on December 05, 2007 at 2 PM PST (UTC-8) with a duration of one hour.
$when = $service-&gt;newWhen();
$when-&gt;startTime = "2007-12-05T14:00:00-08:00";
$when-&gt;endTime="2007-12-05T15:00:00:00-08:00";

// Specify a optional human readable value for the above date
$when-&gt;valueString = "This Afternoon";

// Apply the when property to an event
$event-&gt;when = $when;
            </pre>
<p>
                The <code class="code">when</code> attribute also controls when reminders are sent to a user. Reminders
                are stored in an array and each event may have up to find reminders associated with it.
            </p>
<p>
                For a <code class="code">reminder</code> to be valid, it needs to have two attributes set: <code class="code">method</code>
                and a time. <code class="code">Method</code> can accept one of the following strings: "alert", "email",
                or "sms". The time should be entered as an integer and can be set with either the property
                <code class="code">minutes</code>, <code class="code">hours</code>, <code class="code">days</code>, or <code class="code">absoluteTime</code>.
                However, a valid request may only have one of these attributes set. If a mixed time is
                desired, convert to the most precise unit available. For example, 1 hour and 30 minutes
                should be entered as 90 minutes.
            </p>
<pre class="programlisting">&lt;?php
// Create a new reminder object. It should be set send an email message to the user 10 minutes beforehand.
$reminder = $service-&gt;newReminder();
$reminder-&gt;method = "email";
$reminder-&gt;minutes = "10";

// Apply the reminder to an existing event's when property
$when = $event-&gt;when[0];
$when-&gt;reminders = array($reminder);
            </pre>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.creating_events.recurring"></a>18.4.4.3. Creating Recurring Events</h4></div></div></div>
<p>
                Recurring events are created the same way as single-occurrence events, except a recurrence
                attribute should be provided instead of a where attribute. The recurrence attribute should
                hold a string describing the event's recurrence pattern using properties defined in the
                iCalendar standard (<a href="http://www.ietf.org/rfc/rfc2445.txt" target="_top">RFC 2445</a>).
            </p>
<p>
                Exceptions to the recurrence pattern will usually be specified by a distinct
                <code class="code">recurrenceException</code> attribute. However, the iCalendar standard provides a
                secondary format for defining recurrences, and the possibility that either may be used
                must be accounted for.
            </p>
<p>
                Due to the complexity of parsing recurrence patterns, further information on this them
                is outside the scope of this document. However, more information can be found in the
                <a href="http://code.google.com/apis/gdata/elements.html#gdRecurrence" target="_top">Common Elements section of the Google Data APIs Developer Guide</a>
                , as well as in RFC 2445.
            </p>
<pre class="programlisting">&lt;?php
 // Create a new entry using the calendar service's magic factory method
$event= $service-&gt;newEventEntry();

// Populate the event with the desired information
// Note that each attribute is crated as an instance of a matching class
$event-&gt;title = $service-&gt;newTitle("My Recurring Event");
$event-&gt;where = array($service-&gt;newWhere("Palo Alto, California"));
$event-&gt;content = $service-&gt;newContent(" This is my other awesome event, occurring all-day every Tuesday from 2007-05-01 until 207-09-04. No RSVP required.");

// Set the duration and frequency by specifying a recurrence pattern.

$recurrence = "DTSTART;VALUE=DATE:20070501\r\n" .
        "DTEND;VALUE=DATE:20070502\r\n" .
        "RRULE:FREQ=WEEKLY;BYDAY=Tu;UNTIL=20070904\r\n";

$event-&gt;recurrence = $service-&gt;newRecurrence($recurrence);

// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$newEvent = $service-&gt;insertEvent($event);
            </pre>
</div>
<div class="sect3" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="zend.gdata.calendar.creating_events.quickadd"></a>18.4.4.4. Using QuickAdd</h4></div></div></div>
<p>
                QuickAdd is a feature which allows events to be created using free-form text entry.
                For example, the string "Dinner at Joe's Diner on Thursday" would create an event with
                the title "Dinner", location "Joe's Diner", and date "Thursday". To take advantage of
                QuickAdd, create a new <code class="code">QuickAdd</code> property set to "true" and store the
                freeform text as a <code class="code">content</code> property.
            </p>
<pre class="programlisting">&lt;?php
// Create a new entry using the calendar service's magic factory method
$event= $service-&gt;newEventEntry();

// Populate the event with the desired information
$event-&gt;content= $service-&gt;newContent("Dinner at Joe's Diner on Thursday");
$event-&gt;quickAdd = $service-&gt;newQuickAdd("true");

// Upload the event to the calendar server
// A copy of the event as it is recorded on the server is returned
$newEvent = $service-&gt;insertEvent($event);
            </pre>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar.modifying_events"></a>18.4.5. Modifying Events</h3></div></div></div>
<p>
            Once an instance of an event has been obtained, the event's attributes can be locally modified
            in the same way as when creating an event. Once all modifications are complete, calling the event's
            <code class="code">save()</code> method will upload the changes to the calendar server and return a copy of
            the event as it was created on the server.
        </p>
<p>
            In the event another user has modified the event since the local copy was retrieved,
            <code class="code">save()</code> will fail and the server will return a 409 (Conflict) status code.
            To resolve this a fresh copy of the event must be retrieved from the server before attempting
            to resubmit any modifications.
        </p>
<pre class="programlisting">&lt;?php
// Get the first event in the user's event list
$event = $eventFeed[0];

// Change the title to a new value
$event-&gt;title = $service-&gt;newTitle("Woof!");

// Upload the changes to the server
try {
    $event-&gt;save();
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}
        </pre>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar.deleting_events"></a>18.4.6. Deleting Events</h3></div></div></div>
<p>
            Calendar events can be deleted either by calling the calendar service's
            <code class="code">delete()</code>
            method and providing the edit URL of an event or by calling an existing event's own
            <code class="code">delete()</code>
            method.
        </p>
<p>
            In either case, the deleted event will still show up on a user's private event feed if an
            <code class="code">updateMin</code> query parameter is provided. Deleted events can be distinguished
            from regular events because they will have their <code class="code">eventStatus</code>
            property set to "http://schemas.google.com/g/2005#event.canceled".
        </p>
<pre class="programlisting">&lt;?php
// Option 1: Events can be deleted directly
$event-&gt;delete();
        </pre>
<pre class="programlisting">&lt;?php
// Option 2: Events can be deleted supplying the edit URL of the event to the calendar service, if known
$service-&gt;delete($event-&gt;getEditLink()-&gt;href);
        </pre>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.gdata.calendar.comments"></a>18.4.7. Accessing Event Comments</h3></div></div></div>
<p>
            When using the full event view, comments are not directly stored within an entry. Instead,
            each event contains a URL to it's associated comment feed which must be manually requested.
        </p>
<p>
            Working with comments is fundamentally similar to working with events, with the only
            significant difference being that a different feed and event class should be used and that´
            the additional meta-data for events such as where and when does not exist for comments.
            Specifically, the comment's author is stored in the <code class="code">author</code>
            property, and the comment text is stored in the <code class="code">content</code> property.
        </p>
<pre class="programlisting">&lt;?php
// Extract the comment URL from the first event in a user's feed list
$event = $eventFeed[0];
$commentUrl = $event-&gt;comments-&gt;feedLink-&gt;url;

// Retrieve the comment list for the event
try {
$commentFeed = $service-&gt;getFeed($commentUrl);
} catch (Zend_Gdata_App_Exception $e) {
    echo "Error: " . $e-&gt;getResponse();
}

// Output each comment as an HTML list
echo "&lt;ul&gt;";
foreach ($commentFeed as $comment) {
    echo "&lt;li&gt;&lt;em&gt;Comment By: " . $comment-&gt;author-&gt;name "&lt;/em&gt;&lt;br/&gt;" . $comment-&gt;content . "&lt;/li&gt;";
}
echo "&lt;/ul&gt;";
        </pre>
</div>
</div>
<div class="navfooter"><table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="zend.gdata.clientlogin.html">Prev</a> </td>
<td width="20%" align="center"><a accesskey="u" href="zend.gdata.html">Up</a></td>
<td width="40%" align="right"> <a accesskey="n" href="zend.gdata.docs.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">18.3. Authenticating with ClientLogin </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> 18.5. Using Google Documents List Data API</td>
</tr>
</table></div>
<div class="revinfo"></div>
</body>
</html>
